package io.renren.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by zhangheng on 2017/6/30.
 */
public class DateCompare {

    public static void main(String args[]) {
        int i= compare_date("1995-11-12", "1999-12-11");
        System.out.println("i=="+i);
    }

    public static int compare_date(Object DATE1, Object DATE2) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        try {

            Date dt1 = null;
            Date dt2 = null;
            if(DATE1 instanceof String){
                dt1 = df.parse(DATE1.toString());
            }
            if(DATE2 instanceof String){
                dt2 = df.parse(DATE2.toString());
            }
            if(DATE1 instanceof Date){
                dt1 = (Date)DATE1;
            }
            if(DATE2 instanceof Date){
                dt2 = (Date)DATE2;
            }
            if (dt1.getTime() > dt2.getTime()) {
                System.out.println("dt1 在dt2后");
                return 1;
            } else if (dt1.getTime() < dt2.getTime()) {
                System.out.println("dt1在dt2前");
                return -1;
            } else {
                return 0;
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return 0;
    }
}
